package com.offcn.test;

import java.util.Base64;

public class Base64EncoderAndDecode {
    public static void main(String[] args) {

        System.out.println("原始字符串:" + "admin:admin");

        byte[] encode = Base64.getEncoder().encode("admin:admin".getBytes());
        System.out.println("加密之后的结果:" + new String(encode));

        byte[] decode = Base64.getDecoder().decode("ZG9uZ3lpbWFpOmRvbmd5aW1haQ==".getBytes());
        System.out.println("解密之后的结果:" + new String(decode));

        System.out.println(new String(Base64.getEncoder().encode("{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"admin\":true}".getBytes())));

    }
}
